package com.pv.bfc.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class GetUserDetailsFromContext {

	private Log log = LogFactory.getLog(GetUserDetailsFromContext.class);

	public String getUserName() {
		log.info("IN - GetUserDetailsFromContext - getUserName");
		SecurityContext ctx = SecurityContextHolder.getContext();
		Authentication auth = ctx.getAuthentication();
		log.info("OUT - GetUserDetailsFromContext - getUserName");
		return auth.getName();
	}

	public Object getPrincipal() {
		log.info("IN - GetUserDetailsFromContext - getPrincipal");
		Object principal = SecurityContextHolder.getContext()
				.getAuthentication().getPrincipal();

		log.info("OUT - GetUserDetailsFromContext - getPrincipal");
		return principal;
	}

}
